{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find the K-Beauty of a Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #string #sliding-window"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #字符串 #滑动窗口"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: divisorSubstrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #找到一个数字的 K 美丽值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>一个整数 <code>num</code>&nbsp;的&nbsp;<strong>k&nbsp;</strong>美丽值定义为&nbsp;<code>num</code>&nbsp;中符合以下条件的&nbsp;<strong>子字符串</strong>&nbsp;数目：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>子字符串长度为&nbsp;<code>k</code>&nbsp;。</li>\n",
    "\t<li>子字符串能整除 <code>num</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>给你整数&nbsp;<code>num</code> 和&nbsp;<code>k</code>&nbsp;，请你返回<em>&nbsp;</em><code>num</code>&nbsp;的 k 美丽值。</p>\n",
    "\n",
    "<p>注意：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>允许有&nbsp;<strong>前缀</strong>&nbsp;<strong>0</strong>&nbsp;。</li>\n",
    "\t<li><code>0</code>&nbsp;不能整除任何值。</li>\n",
    "</ul>\n",
    "\n",
    "<p>一个 <strong>子字符串</strong>&nbsp;是一个字符串里的连续一段字符序列。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>num = 240, k = 2\n",
    "<b>输出：</b>2\n",
    "<b>解释：</b>以下是 num 里长度为 k 的子字符串：\n",
    "- \"<em><strong>24</strong></em>0\" 中的 \"24\" ：24 能整除 240 。\n",
    "- \"2<em><strong>40</strong></em>\" 中的 \"40\" ：40 能整除 240 。\n",
    "所以，k 美丽值为 2 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>num = 430043, k = 2\n",
    "<b>输出：</b>2\n",
    "<b>解释：</b>以下是 num 里长度为 k 的子字符串：\n",
    "- \"<em><strong>43</strong></em>0043\" 中的 \"43\" ：43 能整除 430043 。\n",
    "- \"4<em><strong>30</strong></em>043\" 中的 \"30\" ：30 不能整除 430043 。\n",
    "- \"43<em><strong>00</strong></em>43\" 中的 \"00\" ：0 不能整除 430043 。\n",
    "- \"430<em><strong>04</strong></em>3\" 中的 \"04\" ：4 不能整除 430043 。\n",
    "- \"4300<em><strong>43</strong></em>\" 中的 \"43\" ：43 能整除 430043 。\n",
    "所以，k 美丽值为 2 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>1 &lt;= k &lt;= num.length</code>&nbsp;（将&nbsp;<code>num</code>&nbsp;视为字符串）</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-the-k-beauty-of-a-number](https://leetcode.cn/problems/find-the-k-beauty-of-a-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-the-k-beauty-of-a-number](https://leetcode.cn/problems/find-the-k-beauty-of-a-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['240\\n2', '430043\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        ans = 0\n",
    "        for i in range(len(s) + 1 - k):\n",
    "            i = int(s[i:i+k])\n",
    "            if i != 0 and num % i == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        num = str(num)\n",
    "        ans =0\n",
    "\n",
    "        sub_n = num[:k]\n",
    "\n",
    "        if int(sub_n)!=0  and int(num) % int(sub_n) == 0:\n",
    "            ans +=1\n",
    "\n",
    "        # for right,n in enumerate(num[k:],k):\n",
    "        #     # if (int(num[right-1])*10+n)!=0 and int(num) %  (int(num[right-1])*10+n)  == 0 :\n",
    "        #     #     ans+=1\n",
    "        for n in num[k:]:\n",
    "            sub_n = sub_n[1:]+n\n",
    "            if int(sub_n) !=0 and int(num) % int(sub_n) ==0:\n",
    "                ans+=1\n",
    "                \n",
    "\n",
    "        return ans\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(str(num))-k+1):\n",
    "            if int(str(num)[i:i+k]) != 0 and num%int(str(num)[i:i+k]) == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s=str(num)\n",
    "        n=len(s)\n",
    "        ans=0\n",
    "        for i in range(n-k+1):\n",
    "            s1=int(s[i:i+k])\n",
    "            if s1!=0 and num%s1==0:\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n",
    "\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        # num_str = str(num)\n",
    "        # ans = 0\n",
    "        # # 第一个窗口\n",
    "        # sub_str = num_str[:k]\n",
    "        # if int(sub_str) != 0 and num% int(sub_str)==0:\n",
    "        #     ans += 1\n",
    "        # for ch in num_str[k:]:\n",
    "        #     sub_str = sub_str[1:] + ch\n",
    "        #     if int(sub_str) != 0 and num % int(sub_str) == 0:\n",
    "        #         ans += 1\n",
    "        # return ans\n",
    "        s = str(num)\n",
    "        ans = 0\n",
    "        if int(s[:k]) !=0 and num%int(s[:k])==0:\n",
    "            ans += 1\n",
    "        for right in range(k,len(s)):\n",
    "            if int(s[right-k+1:right+1]) !=0 and num%int(s[right-k+1:right+1])== 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "#         s_num = str(num)\n",
    "#         n = len(s_num)\n",
    "#         ans = 0\n",
    "#         i = 0\n",
    "#         while k < n+1:\n",
    "#             if int(s_num[i:k]) != 0 and int(s_num) % int(s_num[i:k]) == 0:\n",
    "#                 ans += 1\n",
    "#             print(s_num[i:k])\n",
    "#             i += 1\n",
    "#             k += 1\n",
    "#         return ans\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        sum1 = 0\n",
    "        for i in range(len(str(num))):\n",
    "            a1 = str(num)[i:i+k]\n",
    "            if len(a1) < k:\n",
    "                break\n",
    "            if int(a1) != 0:\n",
    "                shang, yushu = divmod(num, int(a1))# 元组拆包\n",
    "                if len(a1) == k and yushu == 0:\n",
    "                    sum1 += 1\n",
    "        return sum1\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        raw_num = num\n",
    "        num = list(str(num))\n",
    "        total = num[:k]\n",
    "        cnt =0\n",
    "        if int(\"\".join(total)) % raw_num ==0 or raw_num%int(\"\".join(total))==0:\n",
    "            cnt+=1\n",
    "        for i in range(k,len(num)):\n",
    "            total.pop(0)\n",
    "            total.append(num[i])\n",
    "            total_num = int(\"\".join(total))\n",
    "            if (total_num % raw_num ==0 or raw_num%total_num==0) and total_num!=0:\n",
    "                cnt+=1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        i, ans, s = 0, 0, \"\"\n",
    "        for j, x in enumerate(str(num)):\n",
    "            s += x\n",
    "            if j - i + 1 > k:\n",
    "                s = s[1:]\n",
    "                i += 1\n",
    "            if j - i + 1 == k and int(s) != 0 and num % int(s) == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(0,len(str(num))-k + 1):\n",
    "            n = str(num)[i:i+k]\n",
    "            if int(n) != 0 and num % int(n) == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        nums=str(num)\n",
    "        n=len(nums)\n",
    "        res=0\n",
    "        for i in range(n-k+1):\n",
    "            temp=int(nums[i:i+k])\n",
    "            if temp!=0 and num%temp==0:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        ans=0\n",
    "        for i in range(len(s)-k+1):\n",
    "            if int(s[i:i+k])>0 and num % int(s[i:i+k])==0:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        s_num = str(num)\n",
    "        n = len(s_num)\n",
    "        ans = 0\n",
    "        i = 0\n",
    "        while k < n+1:\n",
    "            if int(s_num[i:k]) != 0 and int(s_num) % int(s_num[i:k]) == 0:\n",
    "                ans += 1\n",
    "            print(s_num[i:k])\n",
    "            i += 1\n",
    "            k += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        res=0\n",
    "        s=str(num)\n",
    "        for i in range(len(s)):\n",
    "            if i>=k-1:\n",
    "                div=int(''.join(s[i+1-k:i+1]))\n",
    "                if div and not num%div: res+=1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        res = 0\n",
    "        r,l = 0,0\n",
    "        cur = ''\n",
    "        s = str(num)\n",
    "        while r<len(s):\n",
    "            cur += s[r]\n",
    "            if r-l+1>=k:\n",
    "                if int(cur)!=0 and num%int(cur)==0:\n",
    "                    res +=1\n",
    "                cur = cur[1:]\n",
    "                l+=1\n",
    "            r += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        nums=str(num)\n",
    "        res=0\n",
    "        n=len(nums)\n",
    "        for i in range(n-k+1):\n",
    "            temp=int(nums[i:i+k])\n",
    "            if temp!=0 and num%temp==0:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        count = 0\n",
    "        num = str(num)\n",
    "        length = len(num)\n",
    "        if length == 1:\n",
    "            return 1\n",
    "        for i in range(length - k + 1):\n",
    "            chang = num[i:i+k]\n",
    "            if int(chang) == 0:\n",
    "                continue\n",
    "            if int(num) % int(chang) == 0:\n",
    "                count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        return sum(num % int(str(num)[i:i+k]) == 0 if int(str(num)[i:i+k]) != 0 else 0 for i in range(len(str(num))-k+1) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        num_str = str(num)\n",
    "\n",
    "        cnt = 0\n",
    "        for i in range(len(num_str) - k + 1):\n",
    "            sub = int(num_str[i:i + k])\n",
    "            #print(sub, num_str[i:i+k])\n",
    "            if sub == 0:\n",
    "                continue\n",
    "            if num % sub == 0:\n",
    "                cnt += 1\n",
    "        \n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)   # num 十进制表示字符串\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n - k + 1):\n",
    "            # 枚举所有长度为 k 的子串\n",
    "            tmp = int(s[i:i+k])\n",
    "            if tmp != 0 and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        #find the amount of slide window whose len=k and can // num\n",
    "        #initiate ans\n",
    "        ans = 0\n",
    "        #first window\n",
    "        numstr = str(num)\n",
    "        slidewindow = numstr[:k]\n",
    "        \n",
    "        if num % int(slidewindow) == 0 and int(slidewindow) != 0:\n",
    "            ans += 1 \n",
    "        for ch in numstr[k:]:\n",
    "            slidewindow = slidewindow[1:] + ch\n",
    "            if int(slidewindow) != 0 and num % int(slidewindow) == 0 :\n",
    "                ans += 1 \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        n=str(num)\n",
    "        s=0\n",
    "        for i in range(len(n)-k+1):\n",
    "            t=n[i:i+k]\n",
    "            if int(t)!=0 and num%int(t)==0:\n",
    "                s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        mark = str(num)\n",
    "        res = 0\n",
    "        for i in range(len(mark)-k+1):\n",
    "            temp = int(mark[i:i+k])\n",
    "            if temp != 0:\n",
    "                if num%temp == 0:\n",
    "                    res += 1\n",
    "        return res\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        cnt = 0\n",
    "        for i in range(len(s)-k+1):\n",
    "            x = int(s[i:i+k])\n",
    "            if x > 0 and num % x == 0:\n",
    "                cnt += 1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        l=0\n",
    "        r=k-1\n",
    "        count = 0\n",
    "        for i in range(0,len(str(num))-k+1):\n",
    "            if int(str(num)[l:r+1])!=0:\n",
    "                if num % int(str(num)[l:r+1])==0:\n",
    "                    count=count+1\n",
    "            l=l+1\n",
    "            r=r+1\n",
    "        return count        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        res = 1 if num % int(nums_pre) == 0 else 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            \n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "#         s_num = str(num)\n",
    "#         n = len(s_num)\n",
    "#         ans = 0\n",
    "#         i = 0\n",
    "#         while k < n+1:\n",
    "#             if int(s_num[i:k]) != 0 and int(s_num) % int(s_num[i:k]) == 0:\n",
    "#                 ans += 1\n",
    "#             print(s_num[i:k])\n",
    "#             i += 1\n",
    "#             k += 1\n",
    "#         return ans\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        sum1 = 0\n",
    "        for i in range(len(str(num))):\n",
    "            a1 = str(num)[i:i+k]\n",
    "            if len(a1) < k:\n",
    "                break\n",
    "            if int(a1) != 0:\n",
    "                shang, yushu = divmod(num, int(a1))# 元组拆包\n",
    "                if len(a1) == k and yushu == 0:\n",
    "                    sum1 += 1\n",
    "        return sum1\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s1 = str(num)\n",
    "        count = 0\n",
    "        start,end = 0,k\n",
    "        for i in range(len(s1)-k+1):\n",
    "            a = int(s1[start+i:end+i])\n",
    "            if a ==0:\n",
    "                continue\n",
    "            else:\n",
    "                if num%a==0:\n",
    "                    count+=1\n",
    "        return (count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        n = len(s)\n",
    "        ans = 0\n",
    "        for i in range(n - k + 1):\n",
    "            if int(s[i: i + k]) != 0 and num % int(s[i: i + k]) == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        l=0  # 滑动窗口左端初始点\n",
    "        r=k-1   # 滑动窗口右端初始点\n",
    "        count = 0   #当前能够整除的子字符串数量 \n",
    "        for i in range(0,len(str(num))-k+1):\n",
    "            if int(str(num)[l:r+1])!=0:\n",
    "                if num % int(str(num)[l:r+1]) == 0:\n",
    "                    count += 1\n",
    "            l += 1\n",
    "            r += 1\n",
    "        return count\n",
    "\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s=str(num)\n",
    "        n=len(s)\n",
    "        ans=0\n",
    "        for i in range(k,n+1):\n",
    "            if int(s[i-k:i])!=0 and num%int(s[i-k:i])==0:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        num1=str(num)\n",
    "        a=0\n",
    "        for i in range(len(num1)-k+1):\n",
    "            num2=int(num1[i:i+k])\n",
    "            if num2!=0:\n",
    "                if num%num2==0:\n",
    "                    a+=1\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        if num % int(nums_pre) == 0:\n",
    "            res = 1\n",
    "        else:\n",
    "            res = 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            print(nums_pre)\n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        l = []\n",
    "        for i in range(0, len(s) - k + 1):\n",
    "            l.append(s[i:i+k])\n",
    "        ans = 0\n",
    "        for i in l:\n",
    "            if int(i) and num % int(i) == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s_num = str(num)\n",
    "        res = 0\n",
    "        for i in range(len(s_num)-k+1):\n",
    "            sub_s = s_num[i:i+k]\n",
    "            print(sub_s)\n",
    "            num_sub = int(sub_s)\n",
    "            if num_sub != 0 and num % num_sub == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        if num % int(nums_pre) == 0:\n",
    "            res = 1\n",
    "        else:\n",
    "            res = 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            print(nums_pre)\n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        tmp=str(num)\n",
    "        res=0\n",
    "        for i in range(len(tmp)-k+1):\n",
    "            val=int(tmp[i:i+k])\n",
    "            if val!=0 and num%val==0:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        ans=0\n",
    "        t=str(num)\n",
    "        lt = len(t)\n",
    "        for i in range(k-1,lt):\n",
    "            n=int(t[i-k+1:i+1])\n",
    "            if n==0:\n",
    "                continue\n",
    "            elif num%n==0:\n",
    "                ans+=1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        str_num = str(num)\n",
    "        res = 0\n",
    "\n",
    "        for i in range(len(str_num)-k+1):\n",
    "            tmp = int(str_num[i:i+k])\n",
    "            if (tmp != 0) and (num % tmp == 0):\n",
    "                res += 1\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        nums = list(str(num))\n",
    "        ans = 0\n",
    "        for i in range(len(nums)-k+1):\n",
    "            bcs = int(''.join(nums[i:i+k]))\n",
    "            if bcs==0:continue\n",
    "            elif num%bcs==0:ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        i, ans = 0, 0\n",
    "        s = str(num)\n",
    "        for j, x in enumerate(s):\n",
    "            if j - i + 1 > k:\n",
    "                i += 1\n",
    "            if j - i + 1 == k and int(s[i:j + 1]) != 0 and num % int(s[i:j + 1]) == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        if num % int(nums_pre) == 0:\n",
    "            res = 1\n",
    "        else:\n",
    "            res = 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            print(nums_pre)\n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        ans = 0\n",
    "        s = str(num)\n",
    "        for i in range(len(s) - k + 1):\n",
    "            n = int(s[i: i + k])\n",
    "            if n == 0:\n",
    "                continue\n",
    "            if num % n == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)   # num 十进制表示字符串\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n - k + 1):\n",
    "            # 枚举所有长度为 k 的子串\n",
    "            tmp = int(s[i:i+k])\n",
    "            if tmp != 0 and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        str_num = str(num)\n",
    "        count = 0\n",
    "        for i in range(len(str_num) - k + 1):\n",
    "            if int(str_num[i: i + k]) == 0:\n",
    "                continue\n",
    "            if num % int(str_num[i: i + k]) == 0:\n",
    "                count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        strnum = str(num)\n",
    "        ans = 0\n",
    "        for i in range(len(strnum)-k+1):\n",
    "            if int(strnum[i:i+k]) and num % int(strnum[i:i+k]) == 0:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def divisorSubstrings(self, num, k):\n",
    "        \"\"\"\n",
    "        :type num: int\n",
    "        :type k: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        sn = str(num)\n",
    "        start, end, n = 0, k, len(sn)\n",
    "        \n",
    "        \n",
    "        \n",
    "      \n",
    "        cnt = 0\n",
    "        while end <= n:\n",
    "            tmp = sn[start: end]\n",
    "            divisor = int(tmp)\n",
    "            \n",
    "            if divisor and num % divisor == 0:\n",
    "                cnt += 1\n",
    "            start += 1\n",
    "            end += 1\n",
    "                \n",
    "        return cnt\n",
    "           \n",
    "        \n",
    "        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        n = num\n",
    "        num, res = str(num), 0\n",
    "        for i in range(k - 1, len(num)):\n",
    "            if int(num[i - k + 1: i + 1]) == 0:\n",
    "                continue\n",
    "            if n % int(num[i - k + 1: i + 1]) == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s=str(num)\n",
    "        n=len(s)\n",
    "        res=0\n",
    "        for i in range(0,n-k+1):\n",
    "            sk=int(s[i:i+k])\n",
    "            if sk!=0 and num%sk==0:\n",
    "                res+=1\n",
    "        return res\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        count=0\n",
    "        string=str(num)\n",
    "        for i in range(len(string)-k+1):\n",
    "            sub=int(string[i:i+k])\n",
    "            if sub!=0 and num%sub==0:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)   # num 十进制表示字符串\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n - k + 1):\n",
    "            # 枚举所有长度为 k 的子串\n",
    "            tmp = int(s[i:i+k])\n",
    "            if tmp != 0 and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        res = 1 if num % int(nums_pre) == 0 else 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            print(nums_pre)\n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "            num=str(num)\n",
    "            count = 0\n",
    "            l=0\n",
    "            r=k\n",
    "            while r<=len(num):\n",
    "                tem=int(num[l:r])\n",
    "                if tem !=0 and int(num) % tem ==0 :\n",
    "                    count+=1\n",
    "                r+=1\n",
    "                l += 1\n",
    "            return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        res = 1 if num % int(nums_pre) == 0 else 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "\n",
    "            if int(nums_pre) != 0 and num % int(nums_pre) == 0:\n",
    "                res += 1\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        left=0\n",
    "        str_num = str(num)\n",
    "        n = len(str_num)\n",
    "        count = 0\n",
    "        while left < n - k + 1:\n",
    "            sub_num = int(str_num[left:left+k])\n",
    "            if sub_num and num%sub_num==0:\n",
    "                count += 1\n",
    "            left+=1\n",
    "        return count\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        if num % int(nums_pre) == 0:\n",
    "            res = 1\n",
    "        else:\n",
    "            res = 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            print(nums_pre)\n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        string = str(num)\n",
    "        n = len(string)\n",
    "        count = 0\n",
    "\n",
    "        for i in range(n-k+1):\n",
    "            tmp = int(string[i:i+k])\n",
    "            if tmp!=0 and num%tmp==0:\n",
    "                count+=1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= str(num)\n",
    "        nums_pre  = nums[:k]\n",
    "\n",
    "        res = 1 if num % int(nums_pre) == 0 else 0\n",
    "            \n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre = nums_pre[1:] + x\n",
    "            if int(nums_pre) != 0 and num % int(nums_pre) == 0:\n",
    "                res += 1\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        cnt = 0\n",
    "        num = str(num)\n",
    "        for i in range(len(num) - k + 1):\n",
    "            if int(num[i:i+k]) != 0 and int(num) % int(num[i:i+k]) == 0:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        n=str(num)\n",
    "        b=len(n)-k+1\n",
    "        #b为字符串个数，n为字符串类型的num\n",
    "        count=0\n",
    "        for i in range(b):\n",
    "            c=int(n[i:k+i])\n",
    "            print(c)\n",
    "            if c==0:\n",
    "                continue\n",
    "            if num%c==0:\n",
    "                count+=1\n",
    "        \n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        stringval = str(num)\n",
    "        result = 0\n",
    "        for i in range(len(stringval) - k + 1):\n",
    "            cur = int(stringval[i: i + k])\n",
    "            if cur == 0:\n",
    "                continue\n",
    "            if num % int(stringval[i: i + k]) == 0:\n",
    "                result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        ans = 0\n",
    "        n = len(str(num))\n",
    "        for i in range(n-k+1):\n",
    "            if int(str(num)[i:i+k])!=0:\n",
    "                if num % int(str(num)[i:i+k]) == 0:\n",
    "                    ans += 1\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "\n",
    "        nums= list(str(num))\n",
    "\n",
    "        nums_pre  = \"\"\n",
    "        for i in nums[:k]:\n",
    "            nums_pre += i\n",
    "\n",
    "        res = 1 if num % int(nums_pre) == 0 else 0\n",
    "            \n",
    "\n",
    "        for right, x in enumerate(nums[k:], k):\n",
    "            nums_pre += x\n",
    "            nums_pre = nums_pre[1:]\n",
    "            \n",
    "            if int(nums_pre) != 0:\n",
    "                if  num % int(nums_pre) == 0:\n",
    "                    res += 1\n",
    "            else:\n",
    "                continue\n",
    "        return res\n",
    "                \n",
    "                \n",
    "            \n",
    "                \n",
    "            \n",
    "            \n",
    "\n",
    "                \n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)   # num 十进制表示字符串\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n - k + 1):\n",
    "            # 枚举所有长度为 k 的子串\n",
    "            tmp = int(s[i:i+k])\n",
    "            if tmp != 0 and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        strnum = str(num)\n",
    "        ans = 0\n",
    "        for i in range(len(strnum) - k + 1):\n",
    "            if int(strnum[i:i + k]) and num % int(strnum[i:i + k]) == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "'''\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        count = 0\n",
    "        num = str(num)\n",
    "        length = len(num)\n",
    "        if length == 1:\n",
    "            return 1\n",
    "        for i in range(length - k + 1):\n",
    "            chang = num[i:i+k]\n",
    "            if int(chang) == 0:\n",
    "                continue\n",
    "            if int(num) % int(chang) == 0:\n",
    "                count += 1\n",
    "        return count\n",
    "'''\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)   # num 十进制表示字符串\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n - k + 1):\n",
    "            # 枚举所有长度为 k 的子串\n",
    "            tmp = int(s[i:i+k])\n",
    "            if tmp != 0 and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def divisorSubstrings(self, num, k):\n",
    "        \"\"\"\n",
    "        :type num: int\n",
    "        :type k: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        sn = str(num)\n",
    "        start, end, n = 0, k, len(sn)\n",
    "        \n",
    "        \n",
    "        \n",
    "      \n",
    "        cnt = 0\n",
    "        while end <= n:\n",
    "            tmp = sn[start: end]\n",
    "            divisor = int(tmp)\n",
    "            \n",
    "            if divisor and num % divisor == 0:\n",
    "                cnt += 1\n",
    "            start += 1\n",
    "            end += 1\n",
    "                \n",
    "        return cnt\n",
    "           \n",
    "        \n",
    "        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        cnt = 0\n",
    "        for x in range(0, len(m:=str(num)), 1):\n",
    "            if len(tmp := m[x:x + k]) != k:\n",
    "                return cnt\n",
    "            if (tpm:=int(tmp)) and not num % tpm:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        count = 0\n",
    "        for i in range(0,len(str(num))-k+1):\n",
    "            if ( num//10**i%10**k)!=0:\n",
    "                if num % ( num//10**i%10**k)==0:\n",
    "                    count=count+1\n",
    "        return count        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        i=ans=0\n",
    "        nums=str(num)\n",
    "        while i<len(nums)-k+1:\n",
    "            temp=int(''.join(nums[i:i+k]))\n",
    "            if not num%temp if temp else False:\n",
    "                ans+=1\n",
    "            i+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        res = 0\n",
    "        m = str(num)\n",
    "        for i in range(len(m) - k + 1):\n",
    "            tmp = int(m[i:i+k])\n",
    "            print(tmp)\n",
    "            if tmp != 0  and num % tmp == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        s = str(num)\n",
    "        ans = 0\n",
    "        for i in range(len(s) + 1 - k):\n",
    "            i = int(s[i:i+k])\n",
    "            if i != 0 and num % i == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divisorSubstrings(self, num: int, k: int) -> int:\n",
    "        count = 0\n",
    "        num = str(num)\n",
    "        for i in range(len(num) - k + 1):\n",
    "            if int(num[i: i + k]) != 0:\n",
    "                if int(num) % int(num[i: i + k]) == 0:\n",
    "                    count += 1\n",
    "        return count"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
